package org.tooyoung.fourone;

import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.RadioGroup;
import android.widget.TextView;

import org.tooyoung.fourone.chat.ChatFragment;
import org.tooyoung.fourone.live.LiveFragment;
import org.tooyoung.fourone.map.MapFragment;
import org.tooyoung.fourone.user.UserFragment;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {

    private ViewPager viewPager;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Intent intent = getIntent();
        String username = intent.getStringExtra("username");
        Log.d("MainActivity", "onCreate:"+username);
        viewPager = (ViewPager) findViewById(R.id.homepage_container);

        TabLayout tabLayout = (TabLayout) findViewById(R.id.tab_layout);
        tabLayout.setupWithViewPager(viewPager);

        List<BaseFragment> fragments = new ArrayList<>();
        LiveFragment liveFragment = new LiveFragment();
        fragments.add(liveFragment);
        MapFragment mapFragment = new MapFragment();
        fragments.add(mapFragment);
        ChatFragment chatFragment = new ChatFragment();
        fragments.add(chatFragment);
        UserFragment userFragment = new UserFragment();
        fragments.add(userFragment);
        CommonFragmentPagerAdapter adapter = new CommonFragmentPagerAdapter(getSupportFragmentManager(), fragments);
        viewPager.setAdapter(adapter);
        Bundle bundle = new Bundle();
        bundle.putString("username",username);
        userFragment.setArguments(bundle);
    }
}
